﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Rites.GameObjects;
using Rites.Networking;

namespace Rites
{
    public class Game
    {
        public event TextOutputDelegate ShowText;
        public event InteractiveOutputDelegate ShowInteractiveText;

        public eGameState gameState;

        public Rites.GameObjects.Map localMap { get; set; }

        //Player specifics
        public Player LocalPlayer { get; set; } //Direct reference to local player
        public Dictionary<int, Player> _players = new Dictionary<int, Player>(); //Indexed list of players, including local player

        //Pre-authentication credentials to login with
        string AuthName = String.Empty;
        string AuthPassword = String.Empty;
        int AuthID = -1;

        //World resource containers for textures, sounds, etc.
        public Dictionary<eTerrainTypes, Texture2D> _terrainTextures = new Dictionary<eTerrainTypes, Texture2D>();
        int tileSize;
        public Texture2D PlayerTexture;
        public Texture2D OtherPlayerTexture;

        //Networking internals
        public long LastSendMessageID;
        string _receiveBuffer = String.Empty;
        public Connection riteConn;

        //FPS vars
        private int _frameCount = 0;
        private double _frameElapsed = 0.0f;
        private string fpsInfo = String.Empty;
        private SpriteFont ChatFont;

        public Game()
        {
            gameState = eGameState.Offline;

            riteConn = new Connection();
            riteConn.DataReceived += new DataReceivedDlg(DataReceivedFromServer);
            riteConn.UserDisconnected += new UserEventDlg(YouHaveBeenDisconnected);
        }

        private void YouHaveBeenDisconnected(object sender)
        {
            ShowText("Disconnected from server.");
        }

        private void DataReceivedFromServer(byte[] data)
        {
            string rawBuffer = System.Text.Encoding.ASCII.GetString(data);
            _receiveBuffer += rawBuffer;

            int messageStart = _receiveBuffer.IndexOf(Constants.BOM);
            int messageStop = _receiveBuffer.IndexOf(Constants.EOM);

            while (messageStart >= 0 && messageStop >= 0)
            {
                string receivedData = _receiveBuffer.Substring(messageStart + Constants.BOM.Length, messageStop - (messageStart + Constants.BOM.Length));
                _receiveBuffer = _receiveBuffer.Replace(Constants.BOM + receivedData + Constants.EOM, "");
                ProcessMessageFromServer(receivedData);
                messageStart = _receiveBuffer.IndexOf(Constants.BOM);
                messageStop = _receiveBuffer.IndexOf(Constants.EOM);
            }

            //Clear the receive buffer if no partial messages found
            if (messageStart == -1)
                _receiveBuffer = string.Empty;
        }

        private void ProcessMessageFromServer(string serverMessage)
        {
            string[] metaParams = serverMessage.Split('~');
            long messageID = long.Parse(metaParams[1]);
            string[] dataParams = metaParams[2].Split('#');

            //Console.WriteLine("Message type: " + System.Enum.GetName(typeof(RitesProtocol), int.Parse(metaParams[0])) + ": " + metaParams[2]);
            //Util.Log("Message type: " + System.Enum.GetName(typeof(RitesProtocol), int.Parse(metaParams[0])));
            //Util.Log("Message ID: " + metaParams[1]);
            //Util.Log("Parameters: " + metaParams[2]);

            switch ((RitesProtocol)(int.Parse(metaParams[0])))
            {
                case RitesProtocol.TextCommand:
                    ShowInteractiveText(dataParams[0], false);
                    break;
                case RitesProtocol.PlayerID:    //Server has assigned us an ID. It's our precioussss....
                    AuthID = int.Parse(dataParams[0]);
                    break;
                case RitesProtocol.TeleportPlayer:
                    LocalPlayer.X = int.Parse(dataParams[0]);
                    LocalPlayer.Y = int.Parse(dataParams[1]);
                    break;
                case RitesProtocol.MapData:
                    ShowText(String.Format("Welcome to TestWorld1, {0}.", LocalPlayer.Name));

                    //Create local map
                    localMap = new Map();
                    localMap.CreateTestMap();
                    //localMap = localMap.Deserialize(dataParams[0]);

                    gameState = eGameState.Playing;

                    break;
                case RitesProtocol.AuthFailed:
                    ShowText("Authentication failed, goodbye.");
                    gameState = eGameState.Offline;
                    break;
                case RitesProtocol.Chat:
                    ShowText(_players[int.Parse(dataParams[0])].Name + ": " + dataParams[1]);
                    break;
                case RitesProtocol.PlayerConnected:
                    int newID = int.Parse(dataParams[0]);
                    if (newID == AuthID) //Our login successful
                    {
                        //Create player finally
                        LocalPlayer = new Player();
                        LocalPlayer.ID = AuthID;
                        LocalPlayer.Name = dataParams[1];
                        LocalPlayer.X = int.Parse(dataParams[2]);
                        LocalPlayer.Y = int.Parse(dataParams[3]);
                        LocalPlayer.DestinationX = LocalPlayer.X;
                        LocalPlayer.DestinationY = LocalPlayer.Y;
                        _players.Add(AuthID, LocalPlayer);

                        riteConn.SendMessage(RitesProtocol.PlayerList, "");
                    }
                    else //A different player logged in
                    {
                        if (!_players.ContainsKey(newID)) //Check if the guy has been added already. This happens if someone logs in while you were typing in your credentials.
                        {
                            Player newPlr = new Player();
                            newPlr.ID = newID;
                            newPlr.Name = dataParams[1];
                            newPlr.X = int.Parse(dataParams[2]);
                            newPlr.Y = int.Parse(dataParams[3]);
                            newPlr.DestinationX = newPlr.X;
                            newPlr.DestinationY = newPlr.Y;
                            _players.Add(newPlr.ID, newPlr);
                            ShowText(newPlr.Name + " has logged in.");
                        }
                    }

                    break;
                case RitesProtocol.PlayerMove:
                    BeginTransition(int.Parse(dataParams[0]), int.Parse(dataParams[1]), int.Parse(dataParams[2]));
                    //_players[int.Parse(dataParams[0])].X = int.Parse(dataParams[1]);
                    //_players[int.Parse(dataParams[0])].Y = int.Parse(dataParams[2]);

                    break;
                case RitesProtocol.PlayerUpdate:
                    Player plrToUpdate;
                    if (_players.ContainsKey(int.Parse(dataParams[0])))
                        plrToUpdate = _players[int.Parse(dataParams[0])];
                    else
                        plrToUpdate = new Player();

                    plrToUpdate.ID = int.Parse(dataParams[0]);
                    plrToUpdate.Name = dataParams[1];
                    plrToUpdate.X = int.Parse(dataParams[2]);
                    plrToUpdate.Y = int.Parse(dataParams[3]);
                    plrToUpdate.DestinationX = plrToUpdate.X;
                    plrToUpdate.DestinationY = plrToUpdate.Y;

                    if (!_players.ContainsKey(int.Parse(dataParams[0])))
                        _players.Add(plrToUpdate.ID, plrToUpdate);

                    break;
                case RitesProtocol.PlayerDisconnected:
                    ShowText(_players[int.Parse(dataParams[0])].Name + " fades away.");
                    _players.Remove(int.Parse(dataParams[0]));
                    break;
                default:
                    ShowText("Error -- Unhandled message type from server: " + System.Enum.GetName(typeof(RitesProtocol), int.Parse(metaParams[0])));
                    break;
            }
        }

        public void BeginTransition(int ID, int newX, int newY)
        {
            //TODO: All currently used variables must be put onto the player object
            if (ID == LocalPlayer.ID)
            {
                LocalPlayer.DestinationX = newX;
                LocalPlayer.DestinationY = newY;
            }
            else
            {
                _players[ID].DestinationX = newX;
                _players[ID].DestinationY = newY;
            }
        }

        public void TextEvent(RitesProtocol msgType, string messageString)
        {
            switch (gameState)
            {
                case eGameState.Offline:
                    ShowText("No commands while offline. It's the rules.");
                    break;
                case eGameState.GetIPAddress:
                    if (ConnectToServer(messageString))
                    {
                        ShowText("Character name: ");
                        gameState = eGameState.GetCharName;
                    }
                    else
                    {
                        ShowText("Unable to connect.");
                        gameState = eGameState.Offline;
                    }
                    break;
                case eGameState.GetCharName:
                    AuthName = messageString;
                    ShowText("Password: ");
                    gameState = eGameState.GetPassword;
                    break;
                case eGameState.GetPassword:
                    AuthPassword = messageString;
                    ShowText("Authenticating...");
                    riteConn.SendMessage(RitesProtocol.PlayerCredentials, AuthName + "#" + AuthPassword);
                    break;
                case eGameState.Playing:
                    riteConn.SendMessage(msgType, messageString);
                    break;
            }
        }

        public bool ConnectToServer(string sIP)
        {
            return riteConn.Connect(sIP, Constants.PORT);
        }

        public void HandleInput(InputHandler inputHandler)
        {
            if (inputHandler.KeyPressed(Keys.Escape))
                ExitGame();

            switch (gameState)
            {
                case eGameState.Playing:
                    ProcessMovementKeys(inputHandler);

                    break;
            }

            inputHandler.FlushBuffer();
        }

        private void ProcessMovementKeys(InputHandler inputHandler)
        {
            if (LocalPlayer.vecPlayerTransition.Length()==0.0f)
            {
                int newX = LocalPlayer.X;
                int newY = LocalPlayer.Y;

                KeyboardState ks = Keyboard.GetState();

                if (inputHandler.KeyPressed(Keys.Left) || ks.IsKeyDown(Keys.Left))
                    newX = LocalPlayer.X - 1;
                else if (inputHandler.KeyPressed(Keys.Right) || ks.IsKeyDown(Keys.Right))
                    newX = LocalPlayer.X + 1;
                else if (inputHandler.KeyPressed(Keys.Up) || ks.IsKeyDown(Keys.Up))
                    newY = LocalPlayer.Y - 1;
                else if (inputHandler.KeyPressed(Keys.Down) || ks.IsKeyDown(Keys.Down))
                    newY = LocalPlayer.Y + 1;

                if (newX != LocalPlayer.X || newY != LocalPlayer.Y)
                {
                    if (localMap.IsValid(newX, newY))
                    {
                        riteConn.SendMessage(RitesProtocol.PlayerMove, String.Format("{0}#{1}#{2}", LocalPlayer.ID, newX, newY));
                    }
                }
            }
        }

        public void ExitGame()
        {
            if (riteConn.Connected)
            {
                riteConn.SendMessage(RitesProtocol.PlayerDisconnected, "");
                riteConn.Disconnect();
            }

            gameState = eGameState.Quitting;
        }

        //Monsters move here etc.
        public void Update(GameTime gameTime)
        {
            switch (gameState)
            {
                case eGameState.Offline:
                    ShowText("Please enter the IP address of the server:");
                    gameState = eGameState.GetIPAddress;
                    break;
                case eGameState.Playing:
                    CalculateTransitions(gameTime);
                    break;
            }
        }

        public void LoadContent(ContentManager content)
        {
            ChatFont = content.Load<SpriteFont>("Fonts//RitesChat");
            PlayerTexture = content.Load<Texture2D>("Textures//Player");
            OtherPlayerTexture = content.Load<Texture2D>("Textures//OtherPlayer");
            LoadTerrainTypes(content);
        }

        private void LoadTerrainTypes(ContentManager content)
        {
            //TODO: Loop through enums, and load by name
            _terrainTextures.Add(eTerrainTypes.Grass, content.Load<Texture2D>("Textures//Terrain//Grass"));
            _terrainTextures.Add(eTerrainTypes.Pebbles, content.Load<Texture2D>("Textures//Terrain//Pebbles"));
            tileSize = _terrainTextures[eTerrainTypes.Grass].Width; //Can be moved out of Draw method if this is an expensive operation
        }

        private void SetPlayerLocation(int playerID, int newX, int newY)
        {
            if (playerID == LocalPlayer.ID)
            {
                LocalPlayer.X = newX;
                LocalPlayer.Y = newY;

                //Stop animations / transitions, in case this was called mid-transition by a teleport spell etc.
                LocalPlayer.vecPlayerTransition.X = 0.0f;
                LocalPlayer.vecPlayerTransition.Y = 0.0f;

                LocalPlayer.DestinationX = newX;
                LocalPlayer.DestinationY = newY;

                ShowInteractiveText(localMap.Locations[LocalPlayer.X, LocalPlayer.Y].Description, true);
            }
            else
            {
                _players[playerID].X = newX;
                _players[playerID].Y = newY;
                _players[playerID].vecPlayerTransition.X = 0.0f;
                _players[playerID].vecPlayerTransition.Y = 0.0f;
                _players[playerID].DestinationX = newX;
                _players[playerID].DestinationY = newY;
            }
        }

        private void CalculateTransitions(GameTime gameTime)
        {
            foreach (Player plr in _players.Values)
            {
                float transitionFraction = (float)gameTime.ElapsedRealTime.TotalMilliseconds/plr.RunSpeed;

                bool destReached = false;

                if (plr.DestinationX < plr.X)
                {
                    plr.vecPlayerTransition.X -= transitionFraction * tileSize;
                    destReached = (plr.vecPlayerTransition.X <= -tileSize);
                }
                else if (plr.DestinationX > plr.X)
                {
                    plr.vecPlayerTransition.X += transitionFraction * tileSize;
                    destReached = (plr.vecPlayerTransition.X >= tileSize);
                }
                else if (plr.DestinationY < plr.Y)
                {
                    plr.vecPlayerTransition.Y -= transitionFraction * tileSize;
                    destReached = (plr.vecPlayerTransition.Y <= -tileSize);
                }
                else if (plr.DestinationY > plr.Y)
                {
                    plr.vecPlayerTransition.Y += transitionFraction * tileSize;
                    destReached = (plr.vecPlayerTransition.Y >= tileSize);
                }

                if (destReached)
                    SetPlayerLocation(plr.ID, plr.DestinationX, plr.DestinationY);
            }
        }

        private void ShowFPSCounter(GameTime gameTime, SpriteBatch spriteBatch)
        {
            _frameCount++;
            _frameElapsed += gameTime.ElapsedRealTime.TotalMilliseconds;
            if (_frameElapsed > 1000.0d)
            {
                fpsInfo = String.Format("{0}\nFPS: {1}", Constants.BUILD_VERSION, _frameCount);
                _frameCount = 0;
                _frameElapsed = 0.0d;
            }

            spriteBatch.DrawString(ChatFont, fpsInfo, new Vector2(0, 0), Color.GreenYellow);
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            

            switch (gameState)
            {
                case eGameState.Playing:
                    int mapEdgeOffsetX = 0; //In pixels
                    int mapEdgeOffsetY = 0; //In pixels
                    int playerRadiusX = (Constants.VIEW_TILES_ACROSS - 1) / 2; //This is the number of tiles between the player and the left/right screen edge
                    int playerRadiusY = (Constants.VIEW_TILES_DOWN - 1) / 2; //This is the number of tiles between the player and the top/bottom screen edges
                    int xIndexStart = LocalPlayer.X - (playerRadiusX + 1); //The X index where we start the map render from, the first rendered row
                    int xIndexStop = xIndexStart + Constants.VIEW_TILES_ACROSS + 1; //We add 1 so we can have an extra row of render, helps scrolling neatness
                    int yIndexStart = LocalPlayer.Y - (playerRadiusY + 1); //The Y index where we start the map render from, the first rendered row
                    int yIndexStop = yIndexStart + Constants.VIEW_TILES_DOWN + 1; //We add 1 so we can have an extra row of render, helps scrolling neatness

                    //Correct xIndexStart for array bounds
                    if (xIndexStart < 0)
                    {
                        mapEdgeOffsetX = Math.Abs(xIndexStart) * tileSize; //Pixel value
                        xIndexStart = 0;
                    }

                    //Correct the X index to stop at if it exceeds array bounds
                    if (xIndexStop > localMap.Width)
                        xIndexStop = localMap.Width;

                    //Correct yIndexStart for array bounds
                    if (yIndexStart < 0)
                    {
                        mapEdgeOffsetY = Math.Abs(yIndexStart) * tileSize; //Pixel value
                        yIndexStart = 0;
                    }

                    //Correct the Y index to stop at if it exceeds array bounds
                    if (yIndexStop > localMap.Height)
                        yIndexStop = localMap.Height;

                    //Pixel values
                    Vector2 vecShiftMapEdge = new Vector2(mapEdgeOffsetX, mapEdgeOffsetY); //Vector to shift the map by (applies to EVERYTHING), so that it is still player centric

                    //RENDER TERRAIN
                    int xCounter = 0;
                    int yCounter = 0;
                    for (int xIndex = xIndexStart; xIndex <= xIndexStop; xIndex++)
                    {
                        for (int yIndex = yIndexStart; yIndex <= yIndexStop; yIndex++)
                        {
                            Vector2 vecTileDefault = new Vector2((xCounter - 1)*tileSize, (yCounter - 1)*tileSize);
                            Vector2 vecShiftTotal = Vector2.Add(vecTileDefault, vecShiftMapEdge);
                            spriteBatch.Draw(_terrainTextures[localMap.Locations[xIndex, yIndex].GroundType], Vector2.Add(vecShiftTotal, Vector2.Negate(LocalPlayer.vecPlayerTransition)), Color.White);
                            yCounter++;
                        }
                        xCounter++;
                        yCounter = 0;
                    }

                    //Prepare player vectors
                    //We subtract 1 again from the X and Y below to adjust for the safety render zones
                    Vector2 vecPlayer = new Vector2((LocalPlayer.X - xIndexStart - 1) * tileSize, (LocalPlayer.Y - yIndexStart - 1) * tileSize);
                    vecPlayer = Vector2.Add(vecPlayer, vecShiftMapEdge);

                    //RENDER OTHER PLAYERS
                    foreach (Player plr in _players.Values)
                    {
                        if (plr.ID != LocalPlayer.ID)
                        {
                            Vector2 vecOtherPlayer = new Vector2((plr.X - xIndexStart - 1) * tileSize, (plr.Y - yIndexStart - 1) * tileSize);
                            //if (vecOtherPlayer.Length() < (Constants.VIEW_TILES_ACROSS + 1) / 2)
                            //{
                                vecOtherPlayer = Vector2.Add(vecOtherPlayer, vecShiftMapEdge);
                                Vector2 vecShiftTotal = Vector2.Add(vecOtherPlayer, Vector2.Negate(LocalPlayer.vecPlayerTransition));
                                vecShiftTotal = Vector2.Add(vecShiftTotal, plr.vecPlayerTransition);
                                spriteBatch.Draw(OtherPlayerTexture, vecShiftTotal, Color.White);
                            //}
                        }
                    }
                    //RENDER PLAYER
                    spriteBatch.Draw(PlayerTexture, vecPlayer, Color.White);

                    //Debug text
                    //Debug info for display
                    string debugString = String.Format(
                        "LocalPlayer.X: {0}\nLocalPlayer.Y: {1}\n" +
                        "LocalPlayer.DestinationX: {2}\nLocalPlayer.DestinationY: {3}\n" +
                        "xIndexStart: {4}\nxIndexStop: {5}\n" +
                        "yIndexStart: {6}\nyIndexStop: {7}\n" +
                        "vecShiftMapEdge: {8}, {9}\n" +
                        "vecPlayer: {10}, {11}\n",
                        LocalPlayer.X, LocalPlayer.Y,
                        LocalPlayer.DestinationX, LocalPlayer.DestinationY,
                        xIndexStart, xIndexStop, yIndexStart, yIndexStop, vecShiftMapEdge.X, vecShiftMapEdge.Y, vecPlayer.X, vecPlayer.Y);

                    spriteBatch.DrawString(ChatFont, debugString, new Vector2(512, 10), Color.White);
                    
                    break;
            }

            ShowFPSCounter(gameTime, spriteBatch);
        }


                //case eGameState.Playing:
                //    Vector2 destVec;

                //    #region Render terrain
                //    int tileWidth = _terrainTextures[eTerrainTypes.Grass].Width; //Can be moved out if more juice needed
                //    int startingX = LocalPlayer.X - ((Constants.VIEW_TILES_ACROSS - 1) / 2) - 1;
                //    int startingY = LocalPlayer.Y - ((Constants.VIEW_TILES_DOWN - 1) / 2) - 1;

                //    //These are used to shift the map right and down if the player approaches the top / left edges
                //    int mapEdgeOffsetX = 0;
                //    int mapEdgeOffsetY = 0;

                //    if (startingX < 0)
                //    {
                //        mapEdgeOffsetX = Math.Abs(startingX) * tileWidth;
                //        startingX = 0;
                //    }

                //    if (startingY < 0)
                //    {
                //        mapEdgeOffsetY = Math.Abs(startingY) * tileWidth;
                //        startingY = 0;
                //    }

                //    //TODO: These can be moved above the resetting of startingX / startingY for optimization
                //    int stoppingX = startingX + Constants.VIEW_TILES_ACROSS + 2;
                //    int stoppingY = startingY + Constants.VIEW_TILES_DOWN + 2;

                //    if (stoppingX > localMap.Width)
                //        stoppingX = localMap.Width;

                //    if (stoppingY > localMap.Height)
                //        stoppingY = localMap.Height;

                //    //Set up global transition offsets
                //    //TODO: Check if any precision/data is lost in this cast
                //    float globalTransAdjustX = (float)(LocalPlayer.vecPlayerTransition.X * tileWidth);
                //    float globalTransAdjustY = (float)(LocalPlayer.vecPlayerTransition.Y * tileWidth);

                //    for (int xTile = startingX; xTile <= stoppingX; xTile++)
                //    {
                //        for (int yTile = startingY; yTile <= stoppingY; yTile++)
                //        {
                //            int destX = (xTile - startingX) * tileWidth;
                //            int destY = (yTile - startingY) * tileWidth;

                //            if (LocalPlayer.vecPlayerTransition.X > 0)
                //                destVec = new Vector2(destX + tileWidth - globalTransAdjustX + mapEdgeOffsetX, destY + mapEdgeOffsetY);
                //            else if (LocalPlayer.vecPlayerTransition.X < 0)
                //                destVec = new Vector2(destX - tileWidth - globalTransAdjustX + mapEdgeOffsetX, destY + mapEdgeOffsetY);
                //            else if (LocalPlayer.vecPlayerTransition.Y > 0)
                //                destVec = new Vector2(destX + mapEdgeOffsetX, destY + tileWidth - globalTransAdjustY + mapEdgeOffsetY);
                //            else if (LocalPlayer.vecPlayerTransition.Y < 0)
                //                destVec = new Vector2(destX + mapEdgeOffsetX, destY - tileWidth - globalTransAdjustY + mapEdgeOffsetY);
                //            else
                //                destVec = new Vector2(destX + mapEdgeOffsetX, destY + mapEdgeOffsetY);

                //            // Adjust for extra render area. We render one extra row/column outside the viewable map area. This is so that when we move 
                //            // we don't see an untextured row/column slide into the screen.
                //            destVec.X = destVec.X - tileWidth;
                //            destVec.Y = destVec.Y - tileWidth;

                //            spriteBatch.Draw(_terrainTextures[localMap.Locations[xTile, yTile].GroundType], destVec, Color.White);
                //        }
                //    }
                //    #endregion

                //    #region Render players
                //    //Local player - always rendered centre screen
                //    destVec = new Vector2(mapEdgeOffsetX + (LocalPlayer.X - startingX - 1) * tileWidth, mapEdgeOffsetY + (LocalPlayer.Y - startingY - 1) * tileWidth);
                //    spriteBatch.Draw(PlayerTexture, destVec, Color.White);

                //    //Other players
                //    //TODO: Don't render players that are not in the current view
                //    foreach (Player otherPlayer in _players.Values)
                //    {
                //        if (otherPlayer.ID != LocalPlayer.ID)
                //        {
                //            if (LocalPlayer.vecPlayerTransition.X > 0) //Left
                //                destVec = new Vector2((mapEdgeOffsetX + (otherPlayer.X - startingX) * tileWidth) - globalTransAdjustX, (mapEdgeOffsetY + (otherPlayer.Y - startingY - 1) * tileWidth) - globalTransAdjustY);
                //            else if (LocalPlayer.vecPlayerTransition.X < 0) //Right
                //                destVec = new Vector2((mapEdgeOffsetX + (otherPlayer.X - startingX - 2) * tileWidth) - globalTransAdjustX, (mapEdgeOffsetY + (otherPlayer.Y - startingY - 1) * tileWidth) - globalTransAdjustY);
                //            else if (LocalPlayer.vecPlayerTransition.Y > 0) //Up
                //                destVec = new Vector2((mapEdgeOffsetX + (otherPlayer.X - startingX - 1) * tileWidth) - globalTransAdjustX, (mapEdgeOffsetY + (otherPlayer.Y - startingY) * tileWidth) - globalTransAdjustY);
                //            else if (LocalPlayer.vecPlayerTransition.Y < 0) //Down
                //                destVec = new Vector2((mapEdgeOffsetX + (otherPlayer.X - startingX - 1) * tileWidth) - globalTransAdjustX, (mapEdgeOffsetY + (otherPlayer.Y - startingY - 2) * tileWidth) - globalTransAdjustY);
                //            else
                //                destVec = new Vector2((mapEdgeOffsetX + (otherPlayer.X - startingX - 1) * tileWidth), (mapEdgeOffsetY + (otherPlayer.Y - startingY - 1) * tileWidth));

                //            spriteBatch.Draw(OtherPlayerTexture, destVec, Color.White);
                //        }
                //    }
                //    #endregion

                //    break;

    }
}